<template>
  <div class="reportFormPage">
    <div id="domid" class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">水泥混凝土凝结时间试验检测报告</div>
        <div class="codeText">
          <tr>
            BGLQ05002F
          </tr>
        </div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>报告编号：</span>
          <span class="placeholder">{{ form.baogbh }}</span>
        </div>
      </div>
      <!-- .........................1111111111111111111111111111111......................................................... -->
      <div class="table-border">
        <table height="220px" class="top-table">
          <tbody>
            <tr>
              <td align="center" width="15%" height="25">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcmc }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="25" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
                <span>；样品数量：</span>
                <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
                <!--                <span>；来样时间：</span>-->
                <!--                <span :class="{ 'placeholder':!form.yangpsj }">{{ form.yangpsj }}</span>-->
              </td>
            </tr>
            <tr>
              <td height="50" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="450px" class="middle-table">
          <tbody>
            <tr trindex="1" width="100%" height="20">
              <td colspan="1" width="15%">混凝土种类</td>
              <td colspan="2">{{ form.hunntzl }}</td>
              <td colspan="1">强度等级</td>
              <td colspan="2">
                <el-input v-model="form.qiangddj" @keydown.native="handleKeyDown($event, 0, 0)" :ref="'0_0'" />
              </td>
            </tr>
            <tr trindex="1" width="100%" height="20">
              <td colspan="1" width="15%">规格尺寸</td>
              <td colspan="2">
                <el-input v-model="form.guigcc" @keydown.native="handleKeyDown($event, 1, 0)" :ref="'1_0'" />
              </td>
              <td colspan="1">养护方式</td>
              <td colspan="2">
                <!-- <el-input v-model="form.yanghtj" @keydown.native="handleKeyDown($event, 1, 1)" :ref="'1_1'" /> -->
                <el-select clearable v-model="form.yanghtj"  class="hide-icon width100 height100" placeholder>
                  <el-option  label="标准养护" value="标准养护"></el-option>
                  <el-option  label="自然养护" value="自然养护"></el-option>
                  <el-option  label="蒸汽养护" value="蒸汽养护"></el-option>
                </el-select>
              </td>
            </tr>

            <tr trindex="1" width="100%" height="20">
              <td colspan="1">序号</td>
              <td colspan="2">检测项目</td>
              <td colspan="1">技术指标</td>
              <td colspan="1">检测结果</td>
              <td colspan="1">结果判定</td>
            </tr>

            <tr trindex="1" width="100%" height="20">
              <td colspan="1">1</td>
              <td colspan="2">初凝时间</td>
              <td colspan="1">-</td>
              <td colspan="1">{{ form.chunsjpjz }}</td>
              <td colspan="1">实测值</td>
            </tr>
            <tr trindex="1" width="100%" height="20">
              <td colspan="1">2</td>
              <td colspan="2">终凝时间</td>
              <td colspan="1">-</td>
              <td colspan="1">{{ form.zhongnsjpjz }}</td>
              <td colspan="1">实测值</td>
            </tr>
            <tr trindex="1" width="100%" height="180">
              <td colspan="1" width="10%">单位面积贯入阻力与测试时间关系曲线</td>
              <td colspan="2" class="echarts-border">
                <span>时间-贯入阻力曲线</span>
                <table-line-log-more-chart :className="'echarts-border'" :chartData="chartData1" :xType="'value'" :xMin="chartData1.xMin" :xMax="chartData1.xMax" :interval="chartData1.interval" />
              </td>
              <td colspan="2" class="echarts-border">
                <span>时间-贯入阻力曲线</span>
                <table-line-log-more-chart :className="'echarts-border'" :chartData="chartData2" :xType="'value'" :xMin="chartData2.xMin" :xMax="chartData2.xMax" :interval="chartData2.interval" />
              </td>
              <td colspan="1" class="echarts-border">
                <span>时间-贯入阻力曲线</span>
                <table-line-log-more-chart :className="'echarts-border'" :chartData="chartData3" :xType="'value'" :xMin="chartData3.xMin" :xMax="chartData3.xMax" :interval="chartData3.interval" />
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="200px" class="bottom-table">
          <tbody>
            <tr>
              <td style="border-bottom-width: 1px">
                <span v-if="isPdf" class="textarea-span">{{ form.jiancjl }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.jiancjl" @focus="handleFocus('jiancjl')" @dblclick.native="getJcjl()" />
              </td>
            </tr>
            <tr>
              <td>
                <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')" />
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">审核：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">审批：</td>
            <td align="left" width="15%"></td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-left: 20px">年</div>
              <div style="display: inline-block; margin-left: 20px">月</div>
              <div style="display: inline-block ;margin-left: 20px">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType" />
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument" />
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType" />
    <bs-judge-base-edit-view ref="bsJudgeBaseEditViewRef" @submit="selectJudgeBaseEdit" :syType="syType" />
  </div>
</template>

<script>
import Bus from "@/utils/bus";
import { handleFocus, emptyConvert, uniqueStr, handleKeyDown } from "@/views/reportForms/utils";
import TableLineLogMoreChart from "@/views/reportForms/components/TableLineLogMoreChart.vue";

import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import { getSnhntNjsjbgBsInfo } from "@/api/reportsnhnt/snhntNjsjbgBsInfo";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView";
import BsJudgeBaseEditView from "@/views/sycs/bsJudgeBase/BsJudgeBaseEditView";
import { computeBiQualification } from "@/api/sycs/biQualification";
import { orderBy } from "lodash";
export default {
  name: "snhntbhwhqlbg",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView,
    BsJudgeBaseEditView,
    TableLineLogMoreChart
  },
  data() {
    return {
      list1: [
        { index: 1, cailmc: "水泥", xinghgg: "P.042.5", shengccjcd: "新泰中联泰丰水泥有限公司", danwyl: "280", zhilb: "1" },
        { index: 2, cailmc: "河砂", xinghgg: "中砂", shengccjcd: "山东省淄博沂源县天湖采砂厂", danwyl: "1700", zhilb: "6.0714" },
        { index: 3, cailmc: "水", xinghgg: "饮用水", shengccjcd: "-", danwyl: "240", zhilb: "0.8571" },
        { index: 4, cailmc: "", xinghgg: "", shengccjcd: "", danwyl: "", zhilb: "" },
        { index: 5, cailmc: "", xinghgg: "", shengccjcd: "", danwyl: "", zhilb: "" }
      ],
      list2: [
        { xuh: 1, jiancxm: "表观密度(kg/m3)", jiszb: "≥1900", jiancjg: "2180", jiegpd: "符合要求" },
        { xuh: 2, jiancxm: "稠度(mm)", jiszb: "70-90", jiancjg: "83", jiegpd: "符合要求" },
        { xuh: 3, jiancxm: "保水率(%)", jiszb: "≥80", jiancjg: "88.0", jiegpd: "符合要求" },
        { xuh: 4, jiancxm: "分层度(mm)", jiszb: "/", jiancjg: "15", jiegpd: "实测值" },
        { xuh: "", jiancxm: "", jiszb: "", jiancjg: "", jiegpd: "" },
        { xuh: "", jiancxm: "", jiszb: "", jiancjg: "", jiegpd: "" },
        { xuh: "", jiancxm: "", jiszb: "", jiancjg: "", jiegpd: "" }
      ],
      jilbh: "",
      form: {
        shiyrq: "2024年03月09日",
        gongcbwyt: "",
        jilbh: "",
        jiancdwmc: "山东路桥集团试验检测中心有限公司泰安高速公路施工总承包项目工地试验室",
        totalPage: "",
        page: "",
        jiancyj: "",
        zhuyyqsbmcjbh: "",
        gongcmc: "汾阳至石楼高速公路",
        yangpmc: "K39+820-K40+440原地面",
        yangpbh: "JTG/T 3610-2019",
        laiysj: "2022年03月09日",
        yangpsl: "3kg",
        yangpzt: "完好无损",
        baDetailVos: {
          155: {}, // 表观密度
          156: {}, // 稠度
          157: {}, // 保水率
          158: {} // 分层度
        }
      },
      chartData1: {
        xName: "时间t（min）",
        yName: "贯入阻力值（MPa）",
        xMin: "auto",
        xMax: "auto",
        interval: 30,
        seriesData: [],
        time: ""
      },
      chartData2: {
        xName: "时间t（min）",
        yName: "贯入阻力值（MPa）",
        xMin: "auto",
        xMax: "auto",
        interval: 30,
        seriesData: [],
        time: ""
      },
      chartData3: {
        xName: "时间t（min）",
        yName: "贯入阻力值（MPa）",
        xMin: "auto",
        xMax: "auto",
        interval: 30,
        seriesData: [],
        time: ""
      },
      twoTableData: {},
      threeTableData: {},
      jiancjl: "检测结论：经检测，该水泥砂浆拌和物的分层度实值为15mm，其他所检参数符合JGJ/T98-2010的技术要求。",
      fjsm: "附加声明：",
      dateText: "2024年05月10日",
      readonly: false,
      list: []
    };
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    syType: {
      type: [String, Number],
      default: () => ""
    }
  },
  watch: {},
  created() {
    this.getInfo();
  },
  mounted() {
    //form 表单
    Bus.$on("setSnhntnjsjForm", (data) => {
      this.form.hunntzl = data.hunntzl;
      //转换初凝、终凝时间格式，min->h+min;
      if (data.chunsjpjz) {
        if (data.chunsjpjz > 60) {
          let bei = (data.chunsjpjz / 60) >> 0;
          let yu = data.chunsjpjz % 60;
          this.form.chunsjpjz = bei + ":" + yu;
        } else {
          this.form.chunsjpjz = data.chunsjpjz;
        }
      } else {
        this.form.chunsjpjz = null;
      }
      if (data.zhongnsjpjz) {
        if (data.zhongnsjpjz > 60) {
          let bei = (data.zhongnsjpjz / 60) >> 0;
          let yu = data.zhongnsjpjz % 60;
          this.form.zhongnsjpjz = bei + ":" + yu;
        } else {
          this.form.zhongnsjpjz = data.zhongnsjpjz;
        }
      } else {
        this.form.zhongnsjpjz = null;
      }
    });
    //图表数据
    Bus.$on("setSnhntnjsjChartData", (info) => {
      const { index, data } = info;
      this["chartData" + index] = data;
    });
    // 检测依据
    Bus.$on("setSnhntnjsjBgjcyj", (data) => {
      const { jiancyj, jiancyjIds } = data;
      const str = jiancyj + (this.form.jiancyj ? "、" + this.form.jiancyj : "");
      const ids = jiancyjIds + (this.form.jiancyjIds ? "," + this.form.jiancyjIds : "");
      this.form.jiancyj = uniqueStr(str, "、");
      this.form.jiancyjIds = uniqueStr(ids, ",");
    });
    // 主要设备
    Bus.$on("setSnhntnjsjBgZhuyyqsbmcjbh", (data) => {
      const { zhuyyqsbmcjbh, shebIds } = data;
      const str = zhuyyqsbmcjbh + (this.form.zhuyyqsbmcjbh ? "、" + this.form.zhuyyqsbmcjbh : "");
      const ids = shebIds + (this.form.shebIds ? "," + this.form.shebIds : "");
      this.form.zhuyyqsbmcjbh = uniqueStr(str, "、");
      this.form.shebIds = uniqueStr(ids, ",");
    });
    // 各报表给报告传值
    Bus.$on("setSjbhwBgJiancjg", (data) => {
      if (data.length <= 0) {
        return;
      }
      let count = 0;
      data.forEach((item) => {
        if (!this.form.baDetailVos[item.key] || !this.form.baDetailVos[item.key].qualId) {
          return;
        }
        if (this.form.baDetailVos[item.key].jiancjg == item.value) {
          count++;
        }
      });

      if (count == data.length) {
        return;
      }
      let keys = [];
      let flg = false;
      data.forEach((item) => {
        if (!this.form.baDetailVos[item.key] || !this.form.baDetailVos[item.key].qualId) {
          return;
        }
        this.form.baDetailVos[item.key].jiancjg = item.value;
        if (!flg && this.form.baDetailVos[item.key].symbolValue) {
          flg = true;
        } else {
          this.form.baDetailVos[item.key].jiegpd = "实测值";
        }
        keys.push(item.key);
      });
      if (flg) {
        this.computeDetectionResult(keys);
      }
    });
  },
  beforeDestroy() {
    // 或者你可以使用其他合适的生命周期钩子
    // 停止监听事件
    Bus.$off("setSnhntnjsjBgjcyj");
    Bus.$off("setSnhntnjsjBgZhuyyqsbmcjbh");
    Bus.$off("setSjbhwBgJiancjg");
    Bus.$off("setSnhntnjsjForm");
    Bus.$off("setSnhntnjsjChartData");
  },
  methods: {
    // 获取详情
    getInfo() {
      getSnhntNjsjbgBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        if (!this.form.jiancjl) {
          this.form.jiancjl = "检测结论：";
        }
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
        for (const key in this.form.baDetailVos) {
          if (Object.hasOwnProperty.call(this.form.baDetailVos, key)) {
            const element = this.form.baDetailVos[key];
            if (!this.form.baDetailVos[key].jiancjg) {
              this.form.baDetailVos[key].jiancjg = "-";
            }
          }
        }
      });
    },
    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
    },
    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
      if (!info || !info.label) {
        return;
      }
      if (!this.form.pandyj) {
        this.form.pandyj = info.label;
      } else {
        if (info && info.label) {
          this.form.pandyj += "、" + info.label;
        }
      }
      // 添加指标 info.list
      let keys = [];
      info.list.forEach((item) => {
       if (this.form.baDetailVos[item.refQualId] && this.form.baDetailVos[item.refQualId].jiancjg) {
          this.form.baDetailVos[item.refQualId].symbolValue = item.symbolValue;
          this.form.baDetailVos[item.refQualId].num1 = item.num1;
          this.form.baDetailVos[item.refQualId].num2 = item.num2;
          keys.push(item.refQualId);
        }
      });
      this.computeDetectionResult(keys);
    },
    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
    },
    // 显示单个技术编辑
    showBsJudgeBaseEditView(key) {
      const info = this.form.baDetailVos[key];
      info.refQualId = info.qualId;
      this.$refs.bsJudgeBaseEditViewRef.init(info);
    },
    // 编辑单个技术指标后赋值
    selectJudgeBaseEdit(info) {
      if (info.qualId) {
        this.form.baDetailVos[info.qualId] = info;
      }
      this.computeDetectionResult([info.qualId]);
    },
    // 计算检测结果
    computeDetectionResult(keys) {
      if (!keys || keys.length <= 0) {
        return;
      }
      const data = keys.map((key) => {
        const info = {
          ...this.form.baDetailVos[key],
          jiancjg: this.form.baDetailVos[key].jiancjg == "-" ? "" : this.form.baDetailVos[key].jiancjg
        };
        return info;
      });
      computeBiQualification(data).then((res) => {
        const returnData = res.data;
        returnData.forEach((item) => {
          if (!item.symbolValue && !item.num1 && !item.num2) {
            item.jiszb = "-";
          }
          item.jiancjg = item.jiancjg ? item.jiancjg : "-";
          this.form.baDetailVos[item.qualId] = item;
        });
      });
    },
    // 获取检测结论
    getJcjl() {
      // 检测结论:依据《公路工程水泥及水泥混凝土试验规程》JTG 3420-2020检测，所检混凝土拌合物初凝时间为6h15min,终凝时间为9h55min。
      let chunsj = " ";
      if (this.form.chunsjpjz) {
        if (this.form.chunsjpjz.includes(":")) {
          chunsj = this.form.chunsjpjz.replace(":", "h") + "min";
        } else {
          chunsj = this.form.chunsjpjz + "min";
        }
      }
      let zhongnsj = " ";
      if (this.form.zhongnsjpjz) {
        if (this.form.zhongnsjpjz.includes(":")) {
          zhongnsj = this.form.zhongnsjpjz.replace(":", "h") + "min";
        } else {
          zhongnsj = this.form.zhongnsjpjz + "min";
        }
      }
      this.form.jiancjl = "检测结论:依据《公路工程水泥及水泥混凝土试验规程》JTG 3420-2020检测，所检混凝土拌合物初凝时间为" + chunsj + "，终凝时间为" + zhongnsj + "。";
      // const form = JSON.parse(JSON.stringify(this.form));
      // queryJcjl(emptyConvert(form)).then((res) => {
      //   const info = res.data;
      //   this.form.jiancjl = info.jiancjl;
      // });
    },
    submitForm() {
      return this.form;
    },
    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [0, 0];
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    }
  }
};
</script>

<style scoped lang="scss">
.echarts-border {
  width: calc((210mm - 40mm - 96px - 6px) / 3 - 4px);
  height: 176px;
  padding: 2px !important;
  background-color: #ffffff !important;
}
</style>
